rm(list = ls())
library(foreign)
library(readstata13)

d <- read.dta13("Barber_Bolton_Thrower_Replication_Data_LSQ.dta")
d <- subset(d, year > 1992 & year < 2014)

d$divided_notveto <- ifelse(d$divided_gov1 == 1 & d$veto_proof == 0, 1, 0)
d$veto_proof_opposed <- ifelse(d$divided_gov1 == 1 & d$veto_proof == 1, 1, 0)

states <- as.character(unique(d$state_fe))
d$divided_notveto <- ifelse(d$state_fe == "Nebraska", 0, d$divided_notveto)
d$veto_proof_opposed <- ifelse(d$state_fe == "Nebraska", 0, d$veto_proof_opposed)

#First 25 states
par(mfrow = c(5, 5), mar = c(2, 4.1, 1, 2.1))
for(j in 1:25){
al <- subset(d, state_fe == states[j])
plot(al$year, al$num_eos, type = "l", xlab = "Year", ylab = states[j],
	xlim = c(1993, 2013))
years <- unique(al$year)

for (i in 1:length(years)){
	len <- years[i]:(years[i]+1)
	if (al$divided_notveto[i] == 1) {
		polygon(c(len, rev(len)), c(c(0, 0), c(700, 700)), col = rgb(0, 0, 0, 0.25),
		border = FALSE)
	}
	else if (al$veto_proof_opposed[i] == 1){
		polygon(c(len, rev(len)), c(c(0, 0), c(700, 700)), col = rgb(0, 0, 0, 0.50),
		border = FALSE)
	}
}

}

###################

#Last 25 states
par(mfrow = c(5, 5), mar = c(2, 4.1, 1, 2.1))
for(j in 26:50){
  al <- subset(d, state_fe == states[j])
  plot(al$year, al$num_eos, type = "l", xlab = "Year", ylab = states[j],
       xlim = c(1993, 2013))
  years <- unique(al$year)
  
  for (i in 1:length(years)){
    len <- years[i]:(years[i]+1)
    if (al$divided_notveto[i] == 1) {
      polygon(c(len, rev(len)), c(c(0, 0), c(700, 700)), col = rgb(0, 0, 0, 0.25),
              border = FALSE)
    }
    else if (al$veto_proof_opposed[i] == 1){
      polygon(c(len, rev(len)), c(c(0, 0), c(700, 700)), col = rgb(0, 0, 0, 0.50),
              border = FALSE)
    }
  }
  
}